﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Media.Imaging;
using AForge.Imaging;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ThreadSafeObjects;
using System.Windows.Media;
using System.Drawing.Drawing2D;
using PixelFormat = System.Drawing.Imaging.PixelFormat;
using System.Runtime.InteropServices;
using BrainTechLLC.ImageOperatorsNonAForgeDependent;


namespace BrainTechLLC.ImageOperatorsNonAForgeDependent
{
    public static partial class FileImageOperators
    {        
        public static Bitmap CreateBitmapWithRenderingMethod(this Bitmap source, int forceWidth, int forceHeight, RenderSettings settings)
        {
            Bitmap bitmap = null;

            switch (settings.RenderingMethod)
            {
                case InternalRenderingMethod.None:
                    {
                        bitmap = ImageOperators.DrawBitmap(source, forceWidth, forceHeight, settings);
                        break;
                    }

                case InternalRenderingMethod.NearestNeighbor:
                    {
                        Timing.BeginTiming();
                        ResizeNearestNeighbor resize = new ResizeNearestNeighbor(forceWidth, forceHeight);
                        bitmap = resize.Apply(source);
                        Timing.EndTiming((d) => AllStats.GetInstance().AddTime("AverageDrawImageTime",d));
                        break;
                    }

                case InternalRenderingMethod.Bilinear:
                    {
                        Timing.BeginTiming();
                        ResizeBilinear resize = new ResizeBilinear(forceWidth, forceHeight);
                        bitmap = resize.Apply(source);
                        Timing.EndTiming((d) => AllStats.GetInstance().AddTime("AverageDrawImageTime", d));
                        break;
                    }

                case InternalRenderingMethod.Bicubic:
                    {
                        Timing.BeginTiming();
                        ResizeBicubic resize = new ResizeBicubic(forceWidth, forceHeight);
                        bitmap = resize.Apply(source);
                        Timing.EndTiming((d) => AllStats.GetInstance().AddTime("AverageDrawImageTime", d));
                        break;
                    }
            }

            return bitmap;
        }
    }
}
